<style>
    #febs-cost xm-select {
        min-height: 25px;
        line-height: 25px;
    }

    #febs-cost xm-select > .xm-label .scroll {
        display: flex;
        padding: 0 30px 0 10px;
    }
</style>

<div class="layui-fluid layui-anim febs-anim" id="businesses-cost" lay-title="缴费列表导出">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="cost-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">批次</label>
                                        <div class="layui-input-inline">
                                            <select name="batchId" lay-filter="cbuBatch" id="cbuBatch">

                                            </select>
                                        </div>
                                    </div>

                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">院校</label>
                                        <div class="layui-input-inline">
                                            <select name="collegeId" lay-filter="cbuCollege" id="cbuCollege">

                                            </select>
                                        </div>
                                    </div>


                                    <div class="layui-inline" style="display: none">
                                        <label class="layui-form-label layui-form-label-sm">学习形式</label>
                                        <div class="layui-input-inline">
                                            <select name="cultivate" lay-filter="cultivate" id="cultivate">

                                            </select>
                                        </div>

                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">层次</label>
                                        <div class="layui-input-inline">
                                            <select name="studyLevelId" lay-filter="cbuLevel" id="cbuLevel">
                                            </select>
                                        </div>
                                    </div>

                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">类别</label>
                                        <div class="layui-input-inline">
                                            <select name="subjectCategoryId" lay-filter="cbuSubcate" id="cbuSubcate">

                                            </select>
                                        </div>
                                    </div>

                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">专业</label>
                                        <div class="layui-input-inline">
                                            <select name="majorId" lay-filter="cbuMajor" id="cbuMajor">
                                            </select>
                                        </div>
                                    </div>


                                    <div>
                                        <div>
                                            <label class="layui-form-label layui-form-label-sm">开始时间</label>
                                            <div class="layui-input-inline">
                                                <input type="text" class="layui-input" id="startdate"
                                                       placeholder="开始时间">
                                            </div>
                                        </div>

                                        <div>
                                            <label class="layui-form-label layui-form-label-sm">截止时间</label>
                                            <div class="layui-input-inline">
                                                <input type="text" class="layui-input" id="enddate" placeholder="开始时间">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action"
                                     id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <div style="margin-top: 50px;width: 500px ">

                        <!--<button lay-event="add_standardFee" style="height: 30px;width: 100px" id="add_standardFee">创建</button>-->
                        <!--<button style="height: 30px;width: 120px" id="copy_standardFee">复制现有套内缴费</button>-->
                        <div class="layui-row">
                            <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action"
                                 id="export">
                                <i class="layui-icon">导出</i>
                            </div>
                        </div>
                    </div>
                    <table lay-filter="costTable" lay-data="{id: 'costTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script data-th-inline="none" type="text/javascript">
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#startdate' //指定元素
            , type: 'datetime'
        });
        laydate.render({
            elem: '#enddate' //指定元素
            , type: 'datetime'
        });
    });
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'febs'], function () {
        let $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#businesses-cost'),
            $reset = $view.find('#reset'),
            $export = $view.find('#export'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createDate', type: null},
            tableIns;
        form.render();
        //initTable();
        //使用ajax获得下拉菜单中的值
        //批次下拉菜单
        /******************************************************/

        batchAll();
        levelAll(0);
        collegeAll(0);
        subcateAll(0);
        majorAll(0);
        cultivateAll();


        function batchAll() {
            $.ajax({
                type: "GET",
                url: "standardFee/batchlist",

                success: function (res) {
                    //console.log("res:" + res)
                    var data = res.data;
                    // console.log(data);
                    if (data.length > 0) {
                        let opt = "<option value='0'>请选择批次</option>";
                        for (var i = 0; i < data.length; i++) {
                            var batch = data[i];
                            opt = opt + "<option value='" + batch.id + "'>" + batch.name + "</option>";

                        }
                        $("#cbuBatch").html(opt);
                    }
                    //渲染下拉菜单，要不然不会出现下拉菜单
                    layui.form.render();
                }
            })
        }


        function cultivateAll() {
            $.ajax({
                type: "GET",
                url: "standardFee/cultivatelist",
                success: function (res) {
                    //console.log("res:" + res)
                    var data = res.data;
                    // console.log(data);
                    if (data.length > 0) {
                        let optc = "<option value='0'>请选择学习形式</option>";
                        for (var i = 0; i < data.length; i++) {
                            var cultivate = data[i];
                            if (cultivate.cultivateName == '成教') {
                                optc = optc + "<option selected value='" + cultivate.id + "'>" + cultivate.cultivateName + "</option>";
                            }
                            optc = optc + "<option value='" + cultivate.id + "'>" + cultivate.cultivateName + "</option>";
                        }
                        $("#cultivate").html(optc);
                    }
                    //渲染下拉菜单，要不然不会出现下拉菜单
                    layui.form.render();
                }
            })
        }

        function collegeAll(batchId) {

            $.ajax({
                type: "GET",
                url: "standardFee/collegelist",
                data: {"batchId": batchId},
                success: function (res) {
                    //console.log("res:" + res)
                    var data = res.data;
                    // console.log(data);
                    if (data.length > 0) {
                        let optc = "<option value='0'>请选择院校</option>";
                        for (var i = 0; i < data.length; i++) {
                            var college = data[i];
                            optc = optc + "<option value='" + college.id + "'>" + college.name + "</option>";

                        }
                        $("#cbuCollege").html(optc);
                    } else {
                        let optc1 = "<option >无记录</option>";
                        $("#cbuCollege").html(optc1);
                    }
                    //渲染下拉菜单，要不然不会出现下拉菜单
                    layui.form.render();
                }
            })

        }

        function levelAll(batchId, collegeId) {
            $.ajax({
                type: "GET",
                url: "standardFee/levallist",
                data: {"batchId": batchId, "collegeId": collegeId},
                success: function (res) {
                    //console.log("level:" + res)
                    var data = res.data;
                    // console.log(data);
                    if (data.length > 0) {
                        let optl = "<option value='0'>请选择层次</option>";
                        for (var i = 0; i < data.length; i++) {
                            var level = data[i];
                            optl = optl + "<option value='" + level.id + "'>" + level.name + "</option>";

                        }
                        $("#cbuLevel").html(optl);
                    }
                    //渲染下拉菜单，要不然不会出现下拉菜单
                    layui.form.render();
                }
            })
        }


        function subcateAll(batchId, collegeId, levelId) {
            $.ajax({
                type: "GET",
                url: "standardFee/subjectcategorylist",
                data: {"batchId": batchId, "collegeId": collegeId, "levelId": levelId},
                success: function (res) {
                    //console.log("level:" + res)
                    var data = res.data;
                    // console.log(data);
                    if (data.length > 0) {
                        let opts = "<option value='0'>请选择类别</option>";
                        for (var i = 0; i < data.length; i++) {
                            var subcate = data[i];
                            opts = opts + "<option value='" + subcate.id + "'>" + subcate.name + "</option>";

                        }
                        $("#cbuSubcate").html(opts);
                        layui.form.render("select");
                    } else {
                        let opts1 = "<option >无记录</option>";
                        $("#cbuSubcate").html(opts1);
                        layui.form.render();

                    }

                }
            })
        }


        function majorAll(batchId, collegeId, levelId, subjectCategoryId) {
            $.ajax({
                type: "GET",
                url: "standardFee/majorlist",
                data: {
                    "batchId": batchId,
                    "collegeId": collegeId,
                    "levelId": levelId,
                    "subjectCategoryId": subjectCategoryId
                },
                success: function (res) {
                    //console.log("level:" + res)
                    var data = res.data;
                    // console.log(data);
                    if (data.length > 0) {
                        let optm = "<option value='0'>请选择专业</option>";
                        for (var i = 0; i < data.length; i++) {
                            var major = data[i];
                            optm = optm + "<option value='" + major.id + "'>" + major.name + "</option>";

                        }
                        $("#cbuMajor").html(optm);
                    } else {
                        let optm1 = "<option >无记录</option>";
                        $("#cbuMajor").html(optm1);

                    }
                    //渲染下拉菜单，要不然不会出现下拉菜单
                    layui.form.render();
                }
            })
        }

        function selectbyexample(batchId, collegeId, levelId, subjectCategoryId, majorId, startdate, enddate) {

            $.ajax({
                type: "GET",
                url: "absenteeCost/selectbyexample",
                data: {
                    "batchId": batchId,
                    "collegeId": collegeId,
                    "levelId": levelId,
                    "subjectCategoryId": subjectCategoryId,
                    "majorId": majorId,
                    "startdate": startdate,
                    "enddate": enddate
                },
                success: function (res) {

                }
            })
        }

        form.on("select(cbuBatch)", function () {
            var a = $("#cbuBatch").val();
            //console.log("dianji："+a);
            collegeAll(a);
            subcateAll(a);
            levelAll(a);
            majorAll(a);
        })
        form.on("select(cbuCollege)", function () {
            var a = $("#cbuBatch").val();
            var b = $("#cbuCollege").val();
            //console.log("dianji："+a);
            levelAll(a, b);
            subcateAll(a, b);
            majorAll(a, b);
        })

        form.on("select(cbuLevel)", function () {
            var a = $("#cbuBatch").val();
            var b = $("#cbuCollege").val();
            var c = $("#cbuLevel").val();
            //console.log("dianji："+a);
            subcateAll(a, b, c);
            majorAll(a, b, c);
        })
        form.on("select(cbuSubcate)", function () {
            var a = $("#cbuBatch").val();
            var b = $("#cbuCollege").val();
            var c = $("#cbuLevel").val();
            var d = $("#cbuSubcate").val();
            //console.log("dianji："+a);
            majorAll(a, b, c, d);
        })


        /******************************************************/


        table.on('sort(standardFee)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });
        //导出数据
        $export.on('click', function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
            params.pageNum = $view.find(".layui-laypage-em").next().html();
            febs.download(ctx + 'absenteeCost/selectbyexample', params, '缴费信息表.xlsx');

        });


        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            tableIns.reload({where: getQueryParams(true), page: {curr: 1}, initSort: sortObject});
        });

        // function initTable() {
        //     tableIns = febs.table.init({
        //         elem: $view.find('table'),
        //         id: 'standardFeeTable',
        //         url: ctx + 'standardFee/list',
        //
        //
        //         cols: [[
        //
        //             {field: 'id', title: '编号', minWidth: 100},
        //             {field: 'batchname', title: '批次', minWidth: 100},
        //             {field: 'collegeName', title: '院校', minWidth: 100},
        //             {field: 'levelName', title: '层次', minWidth: 100},
        //             {field: 'cultivateName', title: '培养方式', minWidth: 100},
        //             {field: 'subjectcategoryName', title: '类别'},
        //             {field: 'majorname', title: '专业', minWidth: 165},
        //             {field: 'paymenExplain', title: '缴费类型', minWidth: 180},
        //             {field: 'originalPrice', title: '应缴金额', minWidth: 180},
        //             {title: '操作', field: 'id', toolbar: '#standardFee-option', minWidth: 140}
        //         ]]
        //     });
        // }

        function getQueryParams(flag) {
            let params = $searchForm.serializeJson();
            return params;
        }


    })
</script>